package ws.very.util.akka.remote

import akka.actor.Actor
import akka.dispatch.MessageQueue
import akka.actor.ActorRef
import akka.dispatch.Envelope
import ws.very.util.akka.mail.WithMsgQ

trait ForwardProxyAc extends Actor {
  def receive = {
    case any => forward(any)
  }
  def forward(any: Any)
}
trait RemoteProxyAc extends ForwardProxyAc {
  def factRemoteAc: ActorRef
  def forward(any: Any) =
    factRemoteAc.forward(any)
}

trait StateRemoteProxyAc extends RemoteProxyAc {
  override def forward(any: Any) =
    if (isOnline)
      super.forward(wrapMsg(any))
    else doOffline(wrapMsg(any))

  def isOnline: Boolean = false
  def wrapMsg(any: Any) = any
  def doOffline(msg: Any)
}

trait Offline2QueueProxyAc extends StateRemoteProxyAc with WithMsgQ {
  def doOffline(msg: Any) = {
    queue.enqueue(factRemoteAc, Envelope(msg, sender, context.system))
  }

}







